The third version does nothing.
The second and third versions cannot be implicitly called by the operator expression (the delete[] operator calls once the function operator delete[] for each of its arguments). Although they can be called explicitly as operator new[] function calls, their default definitions serve no particular purpose - they are provided as counterparts for the operator new[] functions and called accordingly when done automatically.
Global dynamic storage operator functions are special in the standard library:
- All three versions of operator delete[] are declared in the global namespace, not in the std namespace.
- The first and second versions are implicitly declared in every translation unit of a C++ program: The header <new> does not need to be included for them to be present.
- The first and second versions are also replaceable: A program may provide its own definition, that replaces the default one, to produce the result described above.
operator delete[] can be called explicitly as a regular function, but in C++, delete is an operator with a very specific behavior: An expression with the delete operator, first calls the appropriate destructors for each element in its array (if needed), and then calls function operator delete[] to release the storage.
Parameters
- ptr
- Either a null pointer, or a pointer to a memory block to be released, type-casted to a void*.
This pointer value should have been returned by a previous call to operator new[]. - nothrow_constant
- The constant nothrow.
In the default definition, this parameter is ignored, thus the nothrow version performs the exact same functionality as the default version. But both exist, and both may be redefined separately.
nothrow_t is the type of constant nothrow.
- voidptr2
- A void pointer. The value is ignored in the default definition.
Return value
noneExample
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Output:
myclass constructed myclass constructed myclass constructed myclass destroyed myclass destroyed myclass destroyed |
See also
| operator new[] | Allocate storage space for array (function) |
| operator delete | Deallocate storage space (function) |
